package home_page

import (
	"api/internal/respons"
	"context"
	"homepage_srv/homepage"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodSearchLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodSearchLogic {
	return &GoodSearchLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 首页商品搜索
func (l *GoodSearchLogic) GoodSearch(req *types.GoodSearchRequest) (resp *types.Response, err error) {
	search, err := l.svcCtx.HomepageGrpc.GoodSearch(l.ctx, &homepage.GoodSearchRequest{
		StoreName: req.StoreName,
	})

	if err != nil {
		return respons.Error(400, "首页商品搜索失败", nil), err
	}
	return respons.Success(search), nil
}
